home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 5.00 Begin VB.Form Form1 Caption = "Long Lines" ClientHeight = 7845 ClientLeft = 1575 ClientTop = 1935 ClientWidth = 6585 LinkTopic = "Form1" ScaleHeight = 7845 ScaleWidth = 6585 Begin VB.TextBox Text1 Height = 315 Left = 1875 TabIndex = 4 Text = "1034" Top = 900 Width = 1215 End Begin VB.ComboBox Combo1 Height = 315 Left = 375 TabIndex = 3 Text = "Combo1" Top = 900 Width = 1215 End Begin VB.CheckBox Check1 Caption = "&Split" Height = 315 Left = 3375 TabIndex = 2 Top = 900 Width = 1215 End Begin VB.CommandButton Command1 Caption = "&Add Line" Height = 465 Left = 5025 TabIndex = 1 Top = 750 Width = 1215 End Begin VB.ListBox List1 Height = 4545 Left = 450 TabIndex = 0 Top = 1500 Width = 5640 End Begin VB.Label Label3 Caption = "0" Height = 315 Left = 450 TabIndex = 7 Top = 6150 Width = 5565 End Begin VB.Label Label2 Caption = "Length" Height = 165 Left = 1875 TabIndex = 6 Top = 675 Width = 1215 End Begin VB.Label Label1 Caption = "Character" Height = 165 Left = 375 TabIndex = 5 Top = 675 Width = 1215 End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit 'Written by Steve Henning ' http://home.pix.za/sh/sh00001/ ' VB list boxes maximum line length is 1024 characters, (I haven't seen this raised in the documentation). ' The AddToListbox function adds a line with the option of splitting it if it is too long. ' You may use this code anywhere, anyhow, though realize it is at your own risk. ' I cannot be held responsible for any errors, omissions or stupid mistakes on my part, Microsofts or any one elses. ' These 1 lines below can be added to a .bas file, remember to replace the Private with Global Private Const LB_SETHORIZONTALEXTENT = &H194 Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long Private Sub Command1_Click() AddToListbox List1, String$(Val("0" & Text1.Text), Combo1.Text), (Check1.Value = vbChecked) List1.ListIndex = List1.NewIndex End Sub 'Adds a line to a listboxe and sets a horizontal scrollbar so we should be able to view the longest line. ' If bSplitOverMultipleLines is TRUE, lines > 1024 will be split Function AddToListbox(lb As ListBox, sData$, Optional bSplitOverMultipleLines As Boolean = False) Dim sCopy$, sListboxString$ Dim lWidth& Static lLongest& If lb.ListCount = 0 Then lLongest = -1 sCopy = Trim$(sData$) Do While sCopy <> "" sListboxString = Left(sCopy, 1024) lb.AddItem sListboxString lWidth = Len(sListboxString) If lWidth > lLongest Then lLongest = lWidth ' This line of code will add horizontal scroll-bar to the listbox. Call SendMessageLong(lb.hwnd, LB_SETHORIZONTALEXTENT, Me.TextWidth(String$(lLongest + 1, "W")), 0&) End If If Not bSplitOverMultipleLines Then Exit Do ' Get rid of leading 1024 characters that we have just added to the listbox. sCopy = Mid$(sCopy, 1025) Loop End Function Private Sub Form_Load() Dim i% Check1.Value = vbChecked ' Needed for call to LB_SETHORIZONTALEXTENT Me.ScaleMode = vbPixels List1.FontName = "Courier New" Me.FontName = List1.FontName Me.FontSize = List1.FontSize ' Add some data For i = 0 To 9 Combo1.AddItem Chr$(48 + i) Next For i = 0 To 26 Combo1.AddItem Chr$(65 + i) Next Combo1.ListIndex = 0 End Sub Private Sub List1_Click() Label3.Caption = Len(List1.Text) End Sub